package cn.itsource.pethome.dictionary.controller;

import cn.itsource.pethome.basic.util.PageInfo;
import cn.itsource.pethome.basic.util.Result;
import cn.itsource.pethome.dictionary.domain.Systemdictionarytype;
import cn.itsource.pethome.dictionary.query.DctionaryQuery;
import cn.itsource.pethome.dictionary.service.IDctionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/dectionary")
public class DctionaryController {

    @Autowired
    private IDctionaryService dctionaryService ;


    //分页列表
    @PatchMapping
    public PageInfo<Systemdictionarytype> findPageByQuery(@RequestBody DctionaryQuery dctionaryQuery){

        return dctionaryService.findPageByQuery(dctionaryQuery);
    }
    //添加数据
    @PostMapping
    public Result save(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            dctionaryService.save(systemdictionarytype);
            return new Result();

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,e.getMessage());
        }
    }

    //删除数据
    @DeleteMapping//相当于@RequestMapping(value = "/department/{id}",method = RequestMethod.DELETE)
    public Result delete(@RequestBody Systemdictionarytype systemdictionarytype){
        Map<String, Object> map = new HashMap<>();
        try {
            dctionaryService.delete(systemdictionarytype.getId());
            return new Result("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,e.getMessage());
        }

    }



}
